﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.BLL;
using OgilvyOne.Model;

public partial class admin_column_column_list : AdminBasePage
{
    
    public IList datalist = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if(!IsPostBack)
        {
            //权限判断
            PopedomValidate(ColumnBll.COLUMN_LAYERID,QUERY);

            string cid = Request.Params["columnid"];
            string layerid = Request.Params["layerid"];
            if (cid != null && cid != ""
                &&layerid!=null&&layerid!=""
                )
            {
                ColumnBll cbll = new ColumnBll();
                datalist = cbll.GetColumnList(int.Parse(cid));

                this.cnavi.Text = cbll.LayeridColumnNaiv(layerid);
            }
            
        }
        
    }
    protected void addBtn_click(object sender, EventArgs e)
    {
        PopedomValidate(ColumnBll.COLUMN_LAYERID, ADD);
        Response.Redirect("column_detail.aspx?parentid=" + Request.Params["columnid"] + "&layerid=" + Request.Params["layerid"]);
        return;
    }
    protected void modBtn_click(object sender, EventArgs e)
    {
        PopedomValidate(ColumnBll.COLUMN_LAYERID, MOD);
        Response.Redirect("column_detail.aspx?parentid=" + Request.Params["columnid"] + "&columnid=" + Request.Form["id"]+"&layerid=" + Request.Params["layerid"]);
        return;
    }
    protected void orderBtn_click(object sender, EventArgs e)
    {
        PopedomValidate(ColumnBll.COLUMN_LAYERID, MOD);
        ColumnBll cbll = new ColumnBll();
        string cid = Request.Form["id"];
        bool isp = false;
        if (Session["isp"] == null)
        {
            Session["isp"] = DateTime.Now;
        }
        else
        {
            DateTime oldtime = (DateTime)Session["isp"];
            if (DateTime.Now.Ticks - oldtime.Ticks > 2000)
            {
                if (DateTime.Now.Ticks - oldtime.Ticks > 2000 * 60)
                {
                    Session["isp"] = DateTime.Now;
                }
                else
                {
                    isp = true;
                }
            }
        }
        if (cid != null && !isp)
        {
            ColumnModel cm = cbll.GetColumn(int.Parse(cid));
            if (cm!=null&&cbll.ModColumnOrderby(int.Parse(cid), int.Parse(Request.Form["type"])) == true)
            {

                datalist = cbll.GetColumnList(int.Parse(Request.Params["columnid"]));
                this.insertLog("更改栏目排序" + Request.Form["type"] + ":" + cm.Classname);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "incorrect", "<script language='javascript'>alert('失败,不可频繁操作!')</script>");
            }
        }
        
    }
    protected void delBtn_click(object sender, EventArgs e)
    {
        PopedomValidate(ColumnBll.COLUMN_LAYERID, DEL);
        ColumnBll cbll = new ColumnBll();
        string cid = Request.Form["id"];
        if (cid != null)
        {
            ColumnModel cm = cbll.GetColumn(int.Parse(cid));

            if (cm!=null&&cbll.DelColumn(int.Parse(cid)) == true)
            {
                datalist = cbll.GetColumnList(int.Parse(Request.Params["columnid"]));
                this.insertLog("删除栏目:" + cm.Classname);
            }
            else
            {//失败
                ClientScript.RegisterStartupScript(this.GetType(), "incorrect", "<script language='javascript'>alert('删除失败,请确保不存在子栏目或此栏目没有内容!')</script>");
            }
        }
    }
}
